function solveEquation(equation: string): string {
    // 分割
    let leftArr = equation.split('=')[0].replace(/-/g,'+-').split('+')
    let rightArr = equation.split('=')[1].replace(/-/g,'+-').split('+')
    // 合并同类项
    let x:number = collect(leftArr)[0] -  collect(rightArr)[0]
    let num:number = collect(rightArr)[1] -  collect(leftArr)[1]
    console.log(x,num)
    if(x === 0 && num === 0){
        return 'Infinite solutions'
    }else if(x === 0 || num%x != 0){
        return 'No solution'
    }else {
        return 'x='+num/x
    }
    
};

function collect(arr: string[]): number[]{
    let x:number = 0
    let num:number = 0
    arr.forEach(item => {
        if(item.includes('x')){
            // 换算x的系数
            item = item.replace(/^x/,'1').replace(/^-x/,'-1').replace(/x/,'')
            x += Number(item)
        }else {
            num += Number(item)
        }
    })
    return [x,num]
}

const equation: string = "x=x+2"
console.log(solveEquation(equation))